from django.db import models

# Create your models here.
# 商品类别数据模型类
class Types(models.Model):
    id = models.AutoField(primary_key=True)                                # 定义主键id
    firsts = models.CharField('一级类型',max_length=100)        # 定义一级类别字段
    seconds = models.CharField('二级类型',max_length=100)        # 定义二级类别字段

    # 查询返回字符串id
    def __str__(self):
        return str(self.id)

    # 重写类属性
    class Meta:
        verbose_name = '商品类型'
        verbose_name_plural = '商品类型'

# 商品信息数据模型类
class CommodityInfos(models.Model):
    id = models.AutoField(primary_key=True)
    name = models.CharField('商品名称',max_length=100)
    sezes = models.CharField('颜色规格',max_length=100)
    types = models.CharField('商品类型',max_length=100)
    price = models.FloatField('商品价格')
    discount = models.FloatField('折后价格')
    stock = models.IntegerField('存货数量')
    sold = models.IntegerField('已售数量')
    likes = models.IntegerField('收藏数量')
    created = models.DateField('上架日期',auto_now_add=True)
    img = models.FileField('商品主图',upload_to=r'imgs')            # upload_to设置上传图片路径
    details = models.FileField('商品详情介绍图',upload_to=r'details')

    def __str__(self):
        return str(self.id)

    class Meta:
        verbose_name = '商品信息'
        verbose_name_plural = '商品信息'
